New method to marshall and send a Startup Notification message. (from
authorDan Winship <danw@src.gnome.org>
Sun, 29 Apr 2007 18:13:42 +0000 (18:13 +0000)
committerDan Winship <danw@src.gnome.org>
Sun, 29 Apr 2007 18:13:42 +0000 (18:13 +0000)
* gdk/x11/gdkdisplay-x11.c
(gdk_x11_display_broadcast_startup_message): New method to
marshall and send a Startup Notification message. (from #415070)
(gdk_notify_startup_complete_with_id): Use that

svn path=/trunk/; revision=17710

ChangeLog
gdk/x11/gdkdisplay-x11.c
gdk/x11/gdkx.h

index 98f652bec1cea21e70d4b48f2cb236a68f6a5e5a..a1af309b0f59ea970faeaff83eb9471e21f1cee9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-29  Dan Winship  <danw@novell.com>
+
+       * gdk/x11/gdkdisplay-x11.c
+       (gdk_x11_display_broadcast_startup_message): New method to
+       marshall and send a Startup Notification message. (from #415070)
+       (gdk_notify_startup_complete_with_id): Use that
+
 2007-04-29  Mattthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkprintoperation-unix.c 
index ace29b2cfc87e7a08c239fd48d31d7bd56231497..8beb88921231ec179601b594c296d8a7883f73d4 100644 (file)
@@ -930,33 +930,6 @@ _gdk_windowing_set_default_display (GdkDisplay *display)
     }
 }
 
-static char*
-escape_for_xmessage (const char *str)
-{
-  GString *retval;
-  const char *p;
-  
-  retval = g_string_new (NULL);
-
-  p = str;
-  while (*p)
-    {
-      switch (*p)
-        {
-        case ' ':
-        case '"':
-        case '\\':
-          g_string_append_c (retval, '\\');
-          break;
-        }
-
-      g_string_append_c (retval, *p);
-      ++p;
-    }
-
-  return g_string_free (retval, FALSE);
-}
-
 static void
 broadcast_xmessage (GdkDisplay *display,
                    const char *message_type,
@@ -972,6 +945,9 @@ broadcast_xmessage (GdkDisplay *display,
   Atom type_atom_begin;
   Window xwindow;
 
+  if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
+    return;
+
   {
     XSetWindowAttributes attrs;
 
@@ -1045,6 +1021,72 @@ broadcast_xmessage (GdkDisplay *display,
   XFlush (xdisplay);
 }
 
+/**
+ * gdk_x11_display_broadcast_startup_message:
+ * @display: a #GdkDisplay
+ * @message_type: startup notification message type ("new", "change",
+ * or "remove")
+ * @...: a list of key/value pairs (as strings), terminated by a
+ * %NULL key. (A %NULL value for a key will cause that key to be
+ * skipped in the output.)
+ *
+ * Sends a startup notification message of type @message_type to
+ * @display. 
+ *
+ * This is a convenience function for use by code that implements the
+ * freedesktop startup notification specification. Applications should
+ * not normally need to call it directly. See the <ulink
+ * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
+ * Notification Protocol specification</ulink> for
+ * definitions of the message types and keys that can be used.
+ *
+ * Since: 2.12
+ **/
+void
+gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
+                                          const char *message_type,
+                                          ...)
+{
+  GString *message;
+  va_list ap;
+  const char *key, *value, *p;
+
+  message = g_string_new (message_type);
+  g_string_append_c (message, ':');
+
+  va_start (ap, message_type);
+  while ((key = va_arg (ap, const char *)))
+    {
+      value = va_arg (ap, const char *);
+      if (!value)
+       continue;
+
+      g_string_append_printf (message, " %s=\"", key);
+      for (p = value; *p; p++)
+       {
+         switch (*p)
+           {
+           case ' ':
+           case '"':
+           case '\\':
+             g_string_append_c (message, '\\');
+             break;
+           }
+
+         g_string_append_c (message, *p);
+       }
+      g_string_append_c (message, '\"');
+    }
+  va_end (ap);
+
+  broadcast_xmessage (display,
+                     "_NET_STARTUP_INFO",
+                      "_NET_STARTUP_INFO_BEGIN",
+                      message->str);
+
+  g_string_free (message, TRUE);
+}
+
 /**
  * gdk_notify_startup_complete:
  * 
@@ -1064,8 +1106,6 @@ gdk_notify_startup_complete (void)
 {
   GdkDisplay *display;
   GdkDisplayX11 *display_x11;
-  gchar *escaped_id;
-  gchar *message;
 
   display = gdk_display_get_default ();
   if (!display)
@@ -1076,9 +1116,6 @@ gdk_notify_startup_complete (void)
   if (display_x11->startup_notification_id == NULL)
     return;
 
-  if (!G_LIKELY (display_x11->trusted_client))
-    return;
-
   gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
 }
 
@@ -1101,23 +1138,14 @@ void
 gdk_notify_startup_complete_with_id (const gchar* startup_id)
 {
   GdkDisplay *display;
-  gchar *escaped_id;
-  gchar *message;
 
   display = gdk_display_get_default ();
   if (!display)
     return;
 
-  escaped_id = escape_for_xmessage (startup_id);
-  message = g_strdup_printf ("remove: ID=%s", escaped_id);
-  g_free (escaped_id);
-
-  broadcast_xmessage (display,
-                     "_NET_STARTUP_INFO",
-                      "_NET_STARTUP_INFO_BEGIN",
-                      message);
-
-  g_free (message);
+  gdk_x11_display_broadcast_startup_message (display, "remove",
+                                            "ID", startup_id,
+                                            NULL);
 }
 
 /**
index 9563e1b814963d632e11f54dcad8f3a2bdd66a8c..ec85047913d21ebddf623f969bb9f918e88577bc 100644 (file)
@@ -148,6 +148,10 @@ void          gdk_x11_display_set_cursor_theme (GdkDisplay  *display,
                                                const gchar *theme,
                                                const gint   size);
 
+void gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
+                                               const char *message_type,
+                                               ...) G_GNUC_NULL_TERMINATED;
+
 /* returns TRUE if we support the given WM spec feature */
 gboolean gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
                                              GdkAtom    property);